package com.wtpaint.leetcode.查找表;

import java.util.*;

public class GroupAnagrams49 {

    public static List<List<String>> groupAnagrams(String[] strs) {

        Map<String, List<String>> res = new HashMap<>();
        for (String str : strs) {
            char[] temp = str.toCharArray();
            Arrays.sort(temp);
            String s = String.valueOf(temp);
            if (!res.containsKey(s)) {
                res.put(s, new ArrayList<>());
            }
            res.get(s).add(str);
        }
        return new ArrayList<>(res.values());
    }

    public static void main(String[] args) {
        System.out.println("  " + groupAnagrams(new String[]{"eat", "tea", "tan", "ate", "nat", "bat"}));
    }
}
